package cn.io1;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Test04 {
    /*
    * 练习:文本排序
        请将文本信息恢复顺序。
    * */
    public static void main(String[] args) {
        try(
            BufferedReader br = new BufferedReader(new FileReader("move/gusi.txt"));
            BufferedWriter bw = new BufferedWriter(new FileWriter("move/gusi2.txt"))
        ){
            List<String> list = new ArrayList<>();
            String line = null;
            while ((line = br.readLine())!=null){
                list.add(line);
            }
            list.forEach(System.out::println);
            System.out.println("--------------------");
            list.sort((o1, o2)->o1.charAt(0)-o2.charAt(0));
            list.forEach(s->{
                try {
                    bw.write(s);
                    bw.newLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(s);
            });
            // System.out.println(list);
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
